import babel from "rollup-plugin-babel";
import commonjs from "rollup-plugin-commonjs";
import postcss from "rollup-plugin-postcss";
import progress from "rollup-plugin-progress";
import alias from "rollup-plugin-alias";
import { uglify } from "rollup-plugin-uglify";
import postcssUnits from "./css.js";
// import filesize from "rollup-plugin-filesize";
import visualizer from "rollup-plugin-visualizer";
export default {
  input: "./src/main.js",
  output: {
    file: "bundle.js",
  },
  // 将模块视为外部模块，不会打包在库中
  // external: (id) => external.some((e) => id.indexOf(e) === 0),
  plugins: [
    postcss({
      modules: true, // 增加 css-module 功能
      extensions: [".less", ".css"],
      plugins: [postcssUnits()],
      use: [
        [
          "less",
          {
            javascriptEnabled: true,
          },
        ],
      ],
      extract: true, // 无论是 dev 还是其他环境这个配置项都不做 样式的抽离
    }),
    alias({
      resolve: [".jsx", ".js"], //optional, by default this will just look for .js files or folders
      entries: [
        { find: /^i18n\!(.*)/, replacement: "$1.js" },
        // { find: /^i18n\!(.*)/, replacement: "$1.js" }, //remove something in front of the import and append an extension (e.g. loaders, for files that were previously transpiled via the AMD module, to properly handle them in rollup as internals now)
        // //for whatever reason, replace all .js extensions with .wasm
        // { find: /^(.*)\.js$/, replacement: "$1.js" },
      ],
    }),
    progress(),
    visualizer(),
    commonjs({
      include: ["node_modules/**"],
      exclude: ["node_modules/process-es6/**"],
      namedExports: {
        "node_modules/react/index.js": [
          "Children",
          "Component",
          "PropTypes",
          "createElement",
        ],
        "node_modules/react-dom/index.js": ["render"],
      },
    }),
    // uglify(),
    // filesize(),
    babel({
      exclude: "node_modules/**", // 只编译源代码
      runtimeHelpers: true,
    }),
  ],
};
